package com.web.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.web.dao.entity.SysUser;

@Service(value="SysUserDao")
@Scope(value = "singleton")
public class SysUserDao {
	
	@Resource(name="jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	
	public void insert(SysUser user) {
		String sql = "insert into sysuser(id,name,age,email,phone,status) values(?,?,?,?,?,?) ";
		jdbcTemplate.update(sql, new Object[]{user.getId(),user.getName(), user.getAge(), user.getEmail(), user.getPhone(), user.getStatus()});
	}
	
	public void deleteById(int id) {
		String sql = "delete from sysuser where id=?;";
		jdbcTemplate.update(sql, new Object[]{id});
	}

	public void updateSysUser(SysUser user) {
		String sql = "update sysuser set name=?, age=?,email=?,phone=?,status=? where id=?; ";
		jdbcTemplate.update(sql, new Object[]{user.getName(), user.getAge(), user.getEmail(), user.getPhone(), user.getStatus(), user.getId()});
	}
	
	public SysUser selectById(int id) {
		String sql = "select * from sysuser where id = ?;";
		SysUser sysUser = jdbcTemplate.queryForObject(sql, new Object[]{id}, BeanPropertyRowMapper.newInstance(SysUser.class));
		return sysUser;
	}
	
	public List<SysUser> selectByEty(SysUser user) {
		String sql = "select * from sysuser where 1 = 1;";
		List<SysUser> dataList = jdbcTemplate.query(sql, new Object[]{}, BeanPropertyRowMapper.newInstance(SysUser.class));
		return dataList;
	}
}
